'''
Title: Pupil: Eye Tracking Software
cam_test.py
Authors: Moritz Kassner & William Patera
Date: July 12, 2011
Method to test cameras (not used in main, but good for debugging hardware)
'''
import cv
def run():
	
	capture0 = cv.CaptureFromCAM(0)
	cv.SetCaptureProperty(capture0, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
	cv.SetCaptureProperty(capture0, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
	capture1 = cv.CaptureFromCAM(1)
	cv.SetCaptureProperty(capture1, cv.CV_CAP_PROP_FRAME_WIDTH, 1024)
	cv.SetCaptureProperty(capture1, cv.CV_CAP_PROP_FRAME_HEIGHT, 768)
	cv.NamedWindow("c0", 1)
	cv.MoveWindow("c0", 0, 0)
	cv.NamedWindow("c1", 1)
	cv.MoveWindow("c1", 320, 0)
	while True:
		f0 = cv.QueryFrame(capture0)
		cv.ShowImage("c0", f0)
		f1 = cv.QueryFrame(capture1)
		cv.ShowImage("c1", f1)
		image = f0
		image_size = cv.GetSize(image)
		grayscale = cv.CreateImage(image_size, 8, 1)
    		cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)
		seq = cv.FindContours(grayscale, cv.CreateMemStorage(), mode=cv.CV_RETR_LIST, method=cv.CV_CHAIN_APPROX_SIMPLE, offset=(0, 0))

		#print cv.Moments(seq,0)
		c = cv.WaitKey(7) % 0x100
		if c == 27:
			break
			
run()
